/**
 * 
 */
package net.bingosoft.common.upload;

import net.bingosoft.common.json.JSONEncoder;


/**
 * 文件上传响应处理类
 * @author elvis
 */
public class UploadResult {
    private static final JSONEncoder encoder = new JSONEncoder();

    /** 表示上传是否成功 */
    private boolean success;
    
    /** 表示成功或者错误的消息，一般情况下，成功不需要设置消息 */
    private String message;
    
    /** 上传成功后服务器上保存的文件唯一ID，通过这个ID可以从UploadManager中拿到文件路径 */
    private String[] fileid;
    
    public static UploadResult success(){
        return new UploadResult(true,null);
    }
    
    public static UploadResult success(String fileid){
        return new UploadResult(true,null,fileid);
    } 
    
    public static UploadResult success(String[] fileid){
        return new UploadResult(true,null,fileid);
    }       
    
    public static UploadResult failed(String message){
        return new UploadResult(false,message);
    }
    
    public UploadResult(){
        
    }
    
    public UploadResult(boolean success,String message){
        this.success = success;
        this.message = message;
    }
    
    public UploadResult(boolean success,String message,String fileid){
        this(success,message);
        this.fileid = new String[]{fileid};
    }
    
    public UploadResult(boolean success,String message,String[] fileid){
        this(success,message);
        this.fileid = fileid;
    }    

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setFileid(String fileid) {
        this.fileid = new String[]{fileid};
    }
    
    public String[] getFileid() {
        return fileid;
    }

    public void setFileid(String[] fileid) {
        this.fileid = fileid;
    }

    public String toJSON(){
        return encoder.encode(this);
    }
}
